import unittest

from emails import Email

class TestEmail(unittest.TestCase):
    def setUp(self):
        self.email = Email(sender='sender@domain.com', receiver='Samuel Pratt <run.dos.run@hotmail.com>, Phillip Johnson <pip28@me.com>, Bryce McDonald <brycemcd@gmail.com>', subject='subject', body='body')

    def test_constructor(self):
        email = self.email
        self.assertEqual(email.sender, 'sender@domain.com')
        self.assertEqual(email.subject, 'subject')
        self.assertEqual(email.body, 'body')

    def test_attachment(self):
        email = self.email

        self.assertEqual(len(email.files), 0)

        email.attach_file('textfile.txt', '/path/to/file.txt')

        self.assertEqual(len(email.files), 1)
        self.assertIn(('textfile.txt', '/path/to/file.txt'), email.files)

    def test_receiver(self):
        email = self.email
        self.assertIsInstance(email.receiver, str)

    def test_match(self):
        email = self.email

        self.assertTrue(email.match('o'))
        self.assertTrue(email.match('body'))
        self.assertTrue(email.match('subject'))

        self.assertFalse(email.match('asdf'))

if __name__ == '__main__':
    unittest.main()
